package com.ahu.qifei.fund.common.util;

import com.ahu.qifei.fund.common.enums.ResultEnum;
import com.ahu.qifei.fund.common.excetpion.ApiException;
import org.springframework.lang.Nullable;

/**
 * @author ShiQifei
 * @date 2020/11/17 15:11
 */
public class Assert {

    public static void notNull(@Nullable Object object, String message) {
        if (object == null) {
            throw new ApiException(message);
        }
    }

    public static void notNull(@Nullable Object object, ResultEnum resultEnum) {
        if (object == null) {
            throw new ApiException(resultEnum);
        }
    }

    public static void equalsIgnoreCase(@Nullable Object source, Object target, ResultEnum resultEnum) {
        if (source == null || target == null) {
            throw new ApiException(resultEnum.INVALID_PARAM);
        }
        if(!source.toString().equalsIgnoreCase(target.toString())) {
            throw new ApiException(resultEnum);
        }
    }

    public static void equals(@Nullable Object source, Object target, ResultEnum resultEnum) {
        if (source == null || target == null) {
            throw new ApiException(resultEnum.INVALID_PARAM);
        }
        if(!source.toString().equals(target.toString())) {
            throw new ApiException(resultEnum);
        }
    }
}
